package com.kyzh.core.adapters.v3

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.gushenge.core.beans.Game
import com.gushenge.core.dao.MMKVConsts
import com.gushenge.core.dao.MMKVConsts.gid
import com.kyzh.core.R
import com.kyzh.core.adapters.BiaoqianAdapter
import com.kyzh.core.databinding.ItemGameBorderBinding
import com.kyzh.core.pager.gamedetail.GMGameDetailActivity1
import com.kyzh.core.utils.setVisibility
import com.kyzh.core.utils.startGameDetailActivity
import com.kyzh.core.utils.startGameDetailActivity2
import org.jetbrains.anko.toast

class GMGameListBorderAdapter(layout: Int, beans: ArrayList<Game>?): BaseQuickAdapter<Game, BaseDataBindingHolder<ItemGameBorderBinding>>(layout,beans),LoadMoreModule{

    override fun convert(holder: BaseDataBindingHolder<ItemGameBorderBinding>, item: Game) {
        holder.dataBinding?.let {
            it.data = item
            it.bq.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)

            it.bq.adapter = BiaoqianAdapter( item.biaoqian)
            holder.itemView.setOnClickListener {
                item.gid.let {
                    MMKVConsts.gid = item.gid
                    GMGameDetailActivity1.start(context, item.gid, type = "gm")
                }
            }

            if(item.zhekou.isNullOrEmpty()){
                it.btDiscount.setVisibility(false)
            }else{
                if(!item.zhekou.contains("折")){
                    it.btDiscount.text = item.zhekou+"折"
                }else{
                    it.btDiscount.text = item.zhekou
                }
                it.btDiscount.setVisibility(true)
                if(item.zhekou.contains("10")){
                    it.btDiscount.setVisibility(false)
                }
            }

        }
    }
}
